<?
ignore_user_abort(false);

require("config/config.php");
require("lib/lib.mysql.php");
require("lib/lib.common.php");
require("lib/lib.htdb.php");

$db = new db;
$db->connect($db_host, $db_user, $db_pass, $db_name);
$common = new common;
$session = new session($common,$db);

if(!$session->logged_in ||
($common->confirm_uid($_SESSION["uid"],$db)!=0))
   $common->redirect("cms_login.php");

	$food_id = $_REQUEST["food_id"];
	$food_name = $_REQUEST["food_name"];
	$cat_id = $_REQUEST["cat_id"];
	$gmwt_desc1 = $_REQUEST["gmwt_desc1"];
	$gmwt1 = $_REQUEST["gmwt1"];
	$gmwt_desc2 = $_REQUEST["gmwt_desc2"];
	$gmwt2 = $_REQUEST["gmwt2"];
	$calories = $_REQUEST["calories"];
	$saturated_fat = $_REQUEST["saturated_fat"];
	$trans_fat = $_REQUEST["trans_fat"];
	$carbohydrates = $_REQUEST["carbohydrates"];
	$dietary_fiber = $_REQUEST["dietary_fiber"];
	$sugar = $_REQUEST["sugar"];
	$protein = $_REQUEST["protein"];
	$cholesterol = $_REQUEST["cholesterol"];
	$sodium = $_REQUEST["sodium"];
	$iron = $_REQUEST["iron"];
	$vitc = $_REQUEST["vitc"];
	$vitb6 = $_REQUEST["vitb6"];
	$calcium = $_REQUEST["calcium"];
	$vita_ui = $_REQUEST["vita_ui"];

$htdb = new htdb;

$action = $_GET["action"];

switch ($action) {
case "add":

	$food_id = $htdb->add_food($food_name,$cat_id,$gmwt_desc1,$gmwt1,$gmwt_desc2,$gmwt2,$calories,$saturated_fat,$trans_fat,$carbohydrates,$dietary_fiber,$sugar,$protein,$cholesterol,$sodium,$iron,$vitc,$vitb6,$calcium,$vita_ui,$db);

   break;
case "edit":
	$food_id = $_REQUEST["food_id"];
	$update = $htdb->update_food($food_id,$food_name,$cat_id,$gmwt_desc1,$gmwt1,$gmwt_desc2,$gmwt2,$calories,$saturated_fat,$trans_fat,$carbohydrates,$dietary_fiber,$sugar,$protein,$cholesterol,$sodium,$iron,$vitc,$vitb6,$calcium,$vita_ui,$db);

   break;
}

$food = $htdb->view_food($food_id, $db);
$cat_array = $htdb->view_all_categories($db);

ob_start();
require("templates/cms_edit_food.htm");
$output = ob_get_contents();
ob_end_clean();

print $output;

$db->close();
?>